﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using QuanLyKhachSanDAO.DTO;

namespace QuanLyKhachSanDAO.DAO
{
    public class KhachHangDAO
    {
        public static int ThemKhachThue(KhachHangDTO kh)
        {

            int tt = 0;

            DataTable tb = new DataTable();
            if (kh.TinhTrang == true)
                tt = 1;
            string sql = string.Format("insert into khachhang values(N'{0}','{1}',N'{2}',{3},{4}); select @@identity", kh.TenKhachHang, kh.CMND, kh.DiaChi, kh.MaLoaiKhach,tt);
            DataProvider conn = new DataProvider();
            tb = conn.ExecuteQuery(sql);

            int makt=int.Parse(tb.Rows[0][0].ToString());

            return makt;
        }

        public  DataTable LayKhachTheoMa(int makh)
        {
            DataTable kh = new DataTable();
            string sql = string.Format("select kh.MaKhachHang, kh.TenKhachHang, lk.TenLoaiKhach,kh.Cmnd,kh.DiaChi from KhachHang kh, LoaiKhach lk where  lk.maLoaiKhach=kh.MaLoaiKhach and MaKhachHang=" + makh);
            DataProvider conn = new DataProvider();
            kh = conn.ExecuteQuery(sql);
            return kh;
        }

        public DataTable ThemKhachHang(KhachHangDTO kh)
        {
            DataTable tb = new DataTable();
            string sql = string.Format("insert into khachhang(TenKhachHang,DiaChi) values('N{0}',N'{1}'); select @@identity", kh.TenKhachHang, kh.DiaChi);
            DataProvider conn = new DataProvider();
            tb = conn.ExecuteQuery(sql);
            return tb;
        }
    }
}